<template>
  <div class="navBarContainer">
    <div class="navBar">
      <div
        class="barItem"
        v-for="(item, index) in navBarData"
        :key="index"
        :class="index == activeNum ? 'current' : ''"
        @click="clickBarItem(item.path, index)"
      >
        {{ item.name }}
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "NavBar",
  props: {
    navBarData: {
      type: Array,
      default() {
        return [];
      },
    },
  },
  data() {
    return {
      activeNum: 0,
    };
  },

  created() {
    this.navBarData.forEach((item, index) => {
      if (decodeURI(this.$route.path).search(item.path) != -1) {
        this.activeNum = index;
      }
    });
  },

  methods: {
    clickBarItem(path, index) {
      if (index == this.activeNum) return;

      this.activeNum = index;
      this.$emit("clickBarItem", path);
    },
  },
};
</script>

<style lang="less" scoped>
.navBarContainer {
  width: 100%;
  height: 60px;
  position: relative;
}
.navBar {
  display: flex;
  position: relative;
  left: 0;
  top: 0;
  background-color: #fff;
  z-index: 100;
  width: 100%;
  color: rgb(49, 49, 49);
  align-items: center;
  padding: 10px 0 20px 20px;
}
.barItem {
  font-size: 16px;
  margin: 0 3px;
  text-align: center;
  cursor: pointer;
  padding: 6px 20px 5px;
}
.current {
  font-size: 20px;
  color: black;
  font-weight: 600;
  // padding-bottom: 5px;
  border-bottom: 3px solid #ec4141;
  transform: translateY(4px);
}
</style>